package com.yuchen.ishop.service.admin.goods.impl;

import com.yuchen.core.MyPager;
import com.yuchen.core.jdbc.BaseDao;
import com.yuchen.ishop.entity.GoodsXiaoqu;
import com.yuchen.ishop.service.admin.goods.GoodsXiaoquService;
import org.apache.commons.lang.StringUtils;
import org.nutz.dao.Cnd;
import org.nutz.dao.sql.Criteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
@Transactional
public class GoodsXiaoquServiceImpl implements GoodsXiaoquService {

    @Autowired
    private BaseDao dao;

    //@Override
    //public List find() {
    //Condition c = Cnd.where("dicKey", "=", Gobals.SYS_GOODS_TYPE_KEY).asc("sort");
    //return dao.query(GoodsXiaoqu.class,null);
    // }

    @Override
    public MyPager find(Map params, MyPager pager) {
        Criteria cri = Cnd.cri();
        if (params != null && params.size() > 0) {
            if (StringUtils.isNotBlank((String) params.get("name"))) {
                cri.where().andLike("name", (String) params.get("name"));
            }
            if (StringUtils.isNotBlank((String) params.get("propertyCompany"))) {
                cri.where().andLike("propertyCompany", (String) params.get("propertyCompany"));
            }
            if (StringUtils.isNotBlank((String) params.get("developer"))) {
                cri.where().andLike("developer", (String) params.get("developer"));
            }
        }
        return dao.queryPager(GoodsXiaoqu.class, cri, pager);
    }

    @Override
    public GoodsXiaoqu insert(GoodsXiaoqu xiaoqu) {

        return dao.insert(xiaoqu);
    }

    @Override
    public int update(GoodsXiaoqu xiaoqu, boolean isIgnoreNull) {
        if (isIgnoreNull) return dao.updateIgnoreNull(xiaoqu);
        return dao.update(xiaoqu);
    }

    @Override
    public GoodsXiaoqu getById(Long id) {
        return dao.fetch(GoodsXiaoqu.class, id);
    }

    @Override
    public int delete(Long id) {
        return dao.delete(GoodsXiaoqu.class, id);
    }


}
